package com.base.lib.xdialog.utils

import android.view.View
import androidx.datastore.preferences.preferencesDataStore

import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.SharedPreferencesMigration
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStore
import com.base.lib.base.BaseApplication

inline fun onClick(v: View, crossinline onClicked: (v: View) -> Unit) {
    v.setOnClickListener {
        onClicked(it)
    }
}

inline fun onDebouncedClick(v: View, crossinline onClicked: (v: View) -> Unit) {
    v.onDebouncedClick {
        onClicked(it)
    }
}

/**
 * 获取DataStore实例
 * @since  2021/5/12
 */

val Context.dataStore: DataStore<androidx.datastore.preferences.core.Preferences> by preferencesDataStore(
    name = BaseApplication.instance.packageName + "_preferences",
    produceMigrations = { context ->
        listOf(SharedPreferencesMigration(context, BaseApplication.instance.packageName + "_preferences"))
    })

